package edu.iyte.ceng431.hw2.pos.view;

import javax.swing.*;

import edu.iyte.ceng431.hw2.pos.model.SaleLineItem;
import java.awt.*;

public class SaleRenderer extends DefaultListCellRenderer {

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
    public Component getListCellRendererComponent(JList list,
            Object value,
            int index,
            boolean isSelected,
            boolean hasFocus) {

		JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, hasFocus);
		SaleLineItem sli = (SaleLineItem)value; 
        label.setText(sli.getProduct().getName() + " " + sli.getUnitPrice() + " x " +
                sli.getQuantity() + " = " + sli.calculateSum() );
        return label;
    }
}
